﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.Utils;
using System.Collections.Generic;

namespace Ccit.OA.NewsCenter
{
    public class SubmitBLL
    {
        ISubmit oSubmit = null;

        /// <summary>
        /// 根据条件XML获得信息
        /// </summary>
        /// <param name="msClauseAttr">快捷查询XML串
        /// <QUERY>
	    ///     <CAPTION><![CDATA[信息标题]]></CAPTION>
	    ///     <CREATOR>发布人ID</CREATOR>
	    ///     <PICFLAG>导航图片</PICFLAG>
	    ///     <TOPFLAG>置顶标志</TOPFLAG>
	    ///     <NEWSSTATUS>信息状态</NEWSSTATUS>
	    ///     <CATEGORY>栏目范围</CATEGORY>
	    ///     <TIME TYPE="时间范围类型(0:全部时间范围;1:当天;2:当周;3:当月;4:之前N天;5:指定时间范围)">时间段("~"分隔)</TIME>
        /// </QUERY>
        /// </param>
        /// <param name="sColumnNo">选择的栏目编号默认为空(全部栏目)如果不为空XML串中【CATEGORY】设置值无效</param>
        /// <param name="sType">类型0：信息中心</param>
        /// <returns></returns>
        public List<MsNews> GetNewsByClause(MsClauseAttr msClauseAttr,string sColumnNo,string sType)
        {
            CreateObject();
            List<MsNews> lstNews = oSubmit.GetNewsByClause(msClauseAttr, sColumnNo,sType);
            Dispose();
            return lstNews;
        }

        /// <summary>
        /// 根据信息ID获得信息明细
        /// </summary>
        /// <param name="sNewsId"></param>
        /// <returns></returns>
        public MsNews GetNewsByNewsId(string sNewsId)
        {
            CreateObject();
            MsNews msNews = oSubmit.GetNewsByNewsId(sNewsId);
            Dispose();
            return msNews;
        }        

        /// <summary>
        /// 根据信息ID获得浏览记录
        /// </summary>
        /// <param name="sNewsId"></param>
        /// <param name="sUserId"></param>
        /// <param name="sBeginDate"></param>
        /// <param name="sEndDate"></param>
        /// <returns></returns>
        public List<MsViewInfo> GetViewInfoByNewsId(string sNewsId,string sUserId,string sBeginDate,string sEndDate)
        {
            CreateObject();
            List<MsViewInfo> lstViewInfo = oSubmit.GetViewInfoByNewsId(sNewsId,sUserId,sBeginDate,sEndDate);
            Dispose();
            return lstViewInfo;
        }

        /// <summary>
        /// 更改当前置顶状态
        /// </summary>
        /// <param name="sNewsId">信息ID</param>
        /// <param name="sCurrTopFlag">当前置顶状态</param>
        /// <returns></returns>
        public bool ChangeTopFlag(string sNewsId, string sCurrTopFlag)
        {
            CreateObject();
            bool bFlag = oSubmit.ChangeTopFlag(sNewsId, sCurrTopFlag);
            Dispose();
            return bFlag;
        }

        /// <summary>
        /// 根据选择的信息ID删除信息
        /// </summary>
        /// <param name="sNewsIds"></param>
        /// <returns></returns>
        public bool DeleteNewsByIds(string sNewsIds,string sType)
        {
            CreateObject();
            bool bFlag = oSubmit.DeleteNewsByIds(sNewsIds,sType);
            Dispose();
            return bFlag;
        }

        /// <summary>
        /// 根据信息ID获得信息正文
        /// </summary>
        /// <param name="sNewsId"></param>
        /// <returns></returns>
        public MsContent GetNewsContentInfo(string sNewsId)
        {
            CreateObject();
            MsContent msContent = oSubmit.GetNewsContentInfo(sNewsId);
            Dispose();
            return msContent;
        }
        /// <summary>
        /// 发布所选信息
        /// </summary>
        /// <param name="NewsId"></param>
        /// <returns></returns>
        public bool PublicNewsByIds(string sNewsId)
        {
            CreateObject();
            bool bFlag = oSubmit.PublicNewsByIds(sNewsId);
            Dispose();
            return bFlag;
        }

        /// <summary>
        /// 提交或发布信息
        /// </summary>
        /// <param name="sNewsIds"></param>
        /// <returns></returns>
        public bool SubmitNewsByIds(string sNewsIds)
        {
            CreateObject();
            bool bFlag = oSubmit.SubmitNewsByIds(sNewsIds);
            Dispose();
            return bFlag;
        }

        /// <summary>
        /// 撤销所选择的信息
        /// </summary>
        /// <param name="sNewsIds"></param>
        /// <returns></returns>
        public bool RevocationNewsByIds(string sNewsIds)
        {
            CreateObject();
            bool bFlag = oSubmit.RevocationNewsByIds(sNewsIds);
            Dispose();
            return bFlag;
        }
        /// <summary>
        /// 退回所选择的信息
        /// </summary>
        /// <param name="sNewsIds"></param>
        /// <returns></returns>
        public bool ReturnNewsByIds(string sNewsIds)
        {
            CreateObject();
            bool bFlag = oSubmit.ReturnNewsByIds(sNewsIds);
            Dispose();
            return bFlag;
        }

        /// <summary>
        /// 保存信息中心信息
        /// </summary>
        /// <param name="msNews"></param>
        /// <returns></returns>
        public string SaveNewsInfo(MsNews msNews, MsContent msContent)
        {
            CreateObject();
            string sExeResult = oSubmit.SaveNewsInfo(msNews,msContent);
            Dispose();
            return sExeResult;
        }

        /// <summary>
        /// 根据类型及类型ID获得图片信息
        /// </summary>
        /// <param name="sId"></param>
        /// <param name="sType"></param>
        /// <returns></returns>
        public MsImage GetImageByNewsId(string sId,string sType)
        {
            CreateObject();
            MsImage msImage = oSubmit.GetImageByNewsId(sId,sType);
            Dispose();
            return msImage;
        }

        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="msImage"></param>
        /// <param name="sNewsId"></param>
        /// <returns></returns>
        public string UploadImageByNewsId(MsImage msImage,string sNewsId)
        {
            CreateObject();
            string sExeResult = oSubmit.UploadImageByNewsId(msImage,sNewsId);
            Dispose();
            return sExeResult;
        }
        /// <summary>
        /// 删除所选信息
        /// </summary>
        /// <param name="NewsIds"></param>
        /// <returns></returns>

        public bool RemoveNewsByIds(string NewsIds,string sType)
        {
            CreateObject();
            bool bFlag = oSubmit.RemoveNewsByIds(NewsIds, sType);
            Dispose();
            return bFlag;
        }

        /// <summary>
        /// 删除图片
        /// </summary>
        /// <param name="sPicId"></param>
        /// <param name="sNewsId"></param>
        /// <returns></returns>
        public bool DeleteImage(string sPicId, string sId, string sType)
        {
            CreateObject();
            bool bFlag = oSubmit.DeleteImage(sPicId, sId, sType);
            Dispose();
            return bFlag;
        }



        /// <summary>
        /// 保存浏览记录
        /// </summary>
        /// <param name="msViewInfo"></param>
        /// <returns></returns>
        public bool SaveViewRecord(MsViewInfo msViewInfo)
        {
            CreateObject();
            bool bFlag = oSubmit.SaveViewRecord(msViewInfo);
            Dispose();
            return bFlag;
        }

        /// <summary>
        /// 获得信息浏览记录
        /// </summary>
        /// <param name="sNewsId"></param>
        /// <returns></returns>
        public List<MsViewInfo> GetViewInfoByNewsId(string sNewsId,string sUserName)
        {
            CreateObject();
            List<MsViewInfo> lstViewInfo = oSubmit.GetViewInfoByNewsId(sNewsId,sUserName);
            Dispose();
            return lstViewInfo;
        }
        /// <summary>
        /// 返回当前用户具有管理权限的信息列表
        /// </summary>
        /// <param name="Type"></param>
        /// <returns></returns>
        public List<MsNews> GetNewsManageList(MsClauseAttr msClauseAttr, string Type)
        {
            CreateObject();
            List<MsNews> lstNews = oSubmit.GetNewsManageList(msClauseAttr, Type);
            Dispose();
            return lstNews;
        }


        /// <summary>
        /// 创建数据层对象
        /// </summary>
        private void CreateObject()
        {
            if (oSubmit == null)
                oSubmit = (ISubmit)Factory.CreateObject("Ccit.OA.NewsCenter.dll", "Ccit.OA.NewsCenter.Submit", ImportComponentType.DotNetDll, null);
        }

        /// <summary>
        /// 释放对象
        /// </summary>
        private void Dispose()
        {
            if (oSubmit != null)
                oSubmit = null;
        }
    }
}
